<%--
  Created by IntelliJ IDEA.
  User: Administrator
  Date: 2017/6/19
  Time: 9:17
  To change this template use File | Settings | File Templates.
--%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8" %>
<!DOCTYPE HTML>
<jsp:include page="/_meta.jsp"/>
<link href="/lib/easyui/themes/default/easyui.css" rel="stylesheet" type="text/css">
<link href="/lib/easyui/themes/icon.css" rel="stylesheet" type="text/css">
<title>出库单</title>
</head>
<body>
<nav class="breadcrumb"><i class="Hui-iconfont">&#xe67f;</i> 首页 <span class="c-gray en">&gt;</span> 库存管理 <span
        class="c-gray en">&gt;</span> 库存查询 <a class="btn btn-success radius r" style="line-height:1.6em;margin-top:3px"
                                              href="javascript:location.replace(location.href);" title="刷新"><i
        class="Hui-iconfont">&#xe68f;</i></a></nav>
<div class="page-container" style="width:1200px;margin:20px auto">
    <table id="invTable" class="easyui-datagrid" title="库存信息"
           data-options="singleSelect:true,width:820
						 ,iconCls:'icon-search',rownumbers:true,pagination:true,toolbar:'#datetool'
                         ,fitColumns: true">
        <thead>
        <tr>
            <th data-options="field:'invId',width:70" align="center">库存编号</th>
            <th data-options="field:'proBarCode',width:160" align="center">商品条码</th>
            <th data-options="field:'proName',width:90" align="center">商品名</th>
            <th data-options="field:'invCount',width:90" align="center">库存量</th>
            <th data-options="field:'invTopNum',width:90" align="center">上限预警量</th>
            <th data-options="field:'invBottNum',width:90" align="center">下限预警量</th>
            <th data-options="field:'realInvCount',width:90" align="center">实际盘点库存</th>
        </tr>
        </thead>
    </table>
    <div id="datetool" style="padding: 10px">
        仓库&nbsp;&nbsp;<input class="easyui-combobox" id="sto" data-options="valueField:'id',textField:'text'"
                             style="width: 100px"/>&nbsp;&nbsp;&nbsp;&nbsp;
        商品条码&nbsp;&nbsp;<input class="easyui-combobox" id="Inv"
                               data-options="valueField:'proBarCode',textField:'proName'" style="width: 100px"/>&nbsp;&nbsp;&nbsp;&nbsp;
        <a onclick='sear()' class="easyui-linkbutton" iconCls="icon-search">查找</a>
    </div>
</div>
<jsp:include page="/_footer.jsp"/>
<script src="/lib/easyui/jquery.easyui.min.js"></script>
<script src="/lib/easyui/locale/easyui-lang-zh_CN.js"></script>
<!--请在下方写此页面业务相关的脚本-->
<script type="text/javascript">
    var sdata;//留存从服务器回传的数据
    var combData;//留存仓库列表信息
    $(function () {
        $.post("/GetDefaultStoInvServlet", {stoId: "default"}, function (data) {
            sdata = parseTbdata(data);
        });
        $.post("/GetAllStorServlet", {ajax: "comb"}, function (data) {
            combData = $.parseJSON(data);
        });
    });
    function parseTbdata(data) {
        $("#invTable").datagrid({
            data: p(data)
        });
        $("#sto").combobox({
            data: c(data),
            onShowPanel: function () {
                $("#sto").combobox({data: combData});
            },
            onSelect: function (target) {
                $.post("/GetDefaultStoInvServlet", {stoId: target.id}, function (data) {
                    var barCode = [];
                    var jjdata = $.parseJSON(data);
                    for (var i = 0; i < jjdata.length; i++) {
                        barCode[i] = {
                            proBarCode: jjdata[i].product.proBarCode,
                            proName: jjdata[i].product.proName
                        };
                    }
                    $("#Inv").combobox({
                        data: barCode
                    });
                    $("#invTable").datagrid({
                        data: p(data)
                    });
                });
            }
        });
        return data;
    }
    function p(data) {
        var jdata = $.parseJSON(data);
        var invTable = [];
        for (var i = 0; i < jdata.length; i++) {
            invTable[i] = {
                "invId": jdata[i].invId,
                "proBarCode": jdata[i].product.proBarCode,
                "proName": jdata[i].product.proName,
                "invCount": jdata[i].invCount,
                "invTopNum": jdata[i].invTopNum,
                "invBottNum": jdata[i].invBottNum,
                "realInvCount": jdata[i].realInvCount
            }
        }
        return invTable;
    }
    function c(data) {
        var jdata = $.parseJSON(data);
        var cdata = [{
            id: jdata[0].storage.stoId,
            text: jdata[0].storage.stoName + "(默认)",
            "selected": true
        }]
        return cdata;
    }
    var ind = 0;
    function sear() {
        var rows = $("#invTable").datagrid("getRows");
        for (var i = ind; i < rows.length; i++) {
            if (rows[i].proBarCode==$("#Inv").val()) {
                ind = i;
                $("#invTable").datagrid("scrollTo", i)//滚动到这一行记录
                break;
            }
        }
    }
</script>
</body>
</html>
